<template>
	<view class="unit">
		<u-row gutter="50">
			<u-col span="12">
				<u-form v-model="unit">
					<view class="content">
						<h3>请选择单位</h3>
						<view class="lineImg">
							<image src="../static/images/line.png" mode=""></image>
						</view>
						<u-form-item v-for="(item, index) of companyList" :key="index" :label="item.companyTypeName" label-width="140" right-icon="arrow-right" :right-icon-style="{fontSize: '20rpx', color: '#333'}">
							<u-input input-align="right" @click="projectCompany(item)" :disabled="true" v-model="item.companyName" class="u-form-right" />
						</u-form-item>
						<u-form-item label="其他单位" label-width="140" right-icon="arrow-right" :right-icon-style="{fontSize: '20rpx'}">
							<u-input input-align="right" @click="projectCompanyOther" :disabled="true" placeholder="请录入" placeholderStyle="color: #D9D9D9" />
						</u-form-item>
					</view>
				</u-form>
			</u-col>
		</u-row>
	</view>
</template>

<script>
	export default {
		name: 'selectUnit',
		data() {
			return {
				unit: {
					name: 'xx建设单位'
				},
				infoList: {}, // 上一个页面传的数据
				companyList: [] // 单位列表
			}
		},
		// 上一个页面传过来的数据
		onLoad(e) {
			this.infoList = JSON.parse(e.idx)
			this.getcompanyList(this.infoList.projectId) // 获取单位列表
		},
		methods: {
			// 获取单位列表
			getcompanyList(id) {
				let header = {
					"content-type":"application/x-www-form-urlencoded;charset=UTF-8"
				}
				this.$ajax.post({
					url: `/project-info/${id}/companies`,
					header: header
				}).then(res => {
					// console.log(res)
					if(res.code == 200) {
						this.companyList = res.data
					}
				})
			},
			// 点击单位
			projectCompany(item) {
				let dataList = {
					title: item.companyName,
					name: this.infoList.name,
					projectId: this.infoList.projectId, // 项目id
					acceptanceTypeId: this.infoList.acceptanceTypeId, // 验收分类ID
					projectCompanyId: item.projectCompanyId // 工程单位ID
				}
				this.$navJump.navigateTo('./acceptanceProcess?info=' + JSON.stringify(dataList))
			},

			// 点击其他单位
			projectCompanyOther() {
				let dataList = {					title: '其他',					name: this.infoList.name,
					projectId: this.infoList.projectId,
					acceptanceTypeId: this.infoList.acceptanceTypeId,
					projectCompanyId: ''				}
				this.$navJump.navigateTo('./otherAcceptanceProcess?info=' + JSON.stringify(dataList))
			}
		}
	}
</script>

<style lang="scss" scoped>
	.unit {
		margin-top: 20rpx;
		.content {
			background: #FFFFFF;
			padding: 0 30rpx;
			border-radius: 10rpx;
			margin-bottom: 20rpx;
			h3 {
				color: #262626;
				font-size: 30rpx;
				font-weight: 600;
				padding-top: 20rpx;
			}
			.lineImg {
				margin-top: -30rpx;
				image {
					width: 150rpx;
					height: 9.5rpx;
				}
			}
		}
	}
</style>
